﻿using NUnit.Framework;
using StrategicDataSystems.Cloud.Monitoring.HostedServices;
using System;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;


namespace StrategicDataSystems.Cloud.Monitoring.Tests.Given_A_HostedServiceManagementGateway
{

    [TestFixture]
    public class When_GetHostedServicesForSubscription_Is_Called
    {

        [Test]
        [Category("Integration")]
        [Explicit("This test makes a call to the Azure Management API.")]
        public void Should_Return_Hosted_Services()
        {
            string subscriptionId = TestSettings.TestSubscriptionId;
            string certificateThumbprint = TestSettings.TestCertificateThumbprint;

            var managementGateway = new HostedServiceManagementGateway();
            IEnumerable<HostedService> services = managementGateway.GetHostedServicesForSubscription(subscriptionId, certificateThumbprint);

            Assert.IsNotNull(services);
        }

        [Test]
        [Category("Integration")]
        [ExpectedException(ExpectedException=typeof(ArgumentException), 
            ExpectedMessage="Could not locate the Certificate in your Local My Certificate store with the thumbprint provided.")]
        public void Should_Return_ArgumentException_If_CertificateThumbprint_Is_Not_Found()
        {
            string subscriptionId = TestSettings.TestSubscriptionId;
            string certificateThumbprint = "NonValidThumbprint";

            var managementGateway = new HostedServiceManagementGateway();
            IEnumerable<HostedService> services = managementGateway.GetHostedServicesForSubscription(subscriptionId, certificateThumbprint);
        }

        [Test]
        [Category("Integration")]
        [Explicit("This test makes a call to the Azure Management API.")]
        [ExpectedException(ExpectedException = typeof(ArgumentException),
            ExpectedMessage = "Access to the management API was forbidden. Please check your subscriptionID and Thumbprint are correct.")]
        public void Should_Return_An_Exception_If_Credentials_Are_Incorrect()
        {
            string subscriptionId = "Foo";
            string certificateThumbprint = TestSettings.TestCertificateThumbprint;

            var managementGateway = new HostedServiceManagementGateway();
            IEnumerable<HostedService> services = managementGateway.GetHostedServicesForSubscription(subscriptionId, certificateThumbprint);
        }
    }
}
